﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _15.MinMaxSumProductGenericType
{
    class MinMaxSumProductGenericType
    {
        static T Min<T>(params T[] arrayOfParams)
        {
            dynamic minNumber = arrayOfParams[0];
            
            for (int i = 1; i < arrayOfParams.Length; i++)
            {
                
                    if (arrayOfParams[i] < minNumber)
                    {
                        minNumber = arrayOfParams[i];
                    }
            }
            return minNumber;
        }

       
        static T Average<T>(params T[] arrayOfParams)
        {
            dynamic counts = 0;
            dynamic sum = arrayOfParams[0];
            dynamic averageOfNumbers = 0;
            for (int i = 1; i < arrayOfParams.Length; i++)
            {
                sum += arrayOfParams[i];
                counts++;
            }
            averageOfNumbers = sum / counts;
            return averageOfNumbers;
        }
        static T Max<T>(params T[] arrayOfParams)
        {
            dynamic maxNumber = arrayOfParams[0];

            for (int i = 1; i < arrayOfParams.Length; i++)
            {
                if (arrayOfParams[i] > maxNumber)
                {
                    maxNumber = arrayOfParams[i];
                }
            }
            return maxNumber;
        }
       
        static T Sum<T>(params T[] arrayOfParams)
        {
            dynamic sumOfElements = 0;
            for (int i = 1; i < arrayOfParams.Length; i++)
            {
                sumOfElements += arrayOfParams[i];
            }
            return sumOfElements;
        }
        static T Product<T>(params T[] arrayOfParams)
        {
            dynamic product = 1;
            for (int i = 1; i < arrayOfParams.Length; i++)
            {
                product *= arrayOfParams[i];
            }
           
            return product;
        }
        static void Main()
        {
            //Console.WriteLine("Length: ");
            //int n = int.Parse(Console.ReadLine());
            //dynamic[] sequence;
            //sequence = new dynamic[n];
            //for (int i = 0; i < n; i++)
            //{
            //    Console.Write("sequence[{0}]=",i);
            //    sequence[i] = int.Parse(Console.ReadLine());
            //}
            //Console.WriteLine("Min of sequence array: {0}", Min(sequence));
            //Console.WriteLine("Max of sequence array : {0}", Max(sequence));
            //Console.WriteLine("Average of sequence array: {0:0.000}", Average(sequence));
            //Console.WriteLine("Sum of sequence array: {0}", Sum(sequence));
            //Console.WriteLine("Product of sequence array : {0}", Product(sequence));
            //Console.WriteLine();
            Console.WriteLine("Min of params: {0}", Min(5.5, 6, 21, 3));
            Console.WriteLine("Max of params : {0}", Max(5, 6, 21, 3));
            Console.WriteLine("Average of params : {0:0.000}", Average(5, 6, 21, 3));
            Console.WriteLine("Sum of params: {0}", Sum(5, 6, 21, 3));
            Console.WriteLine("Product of params : {0}", Product(5, 6, 21, 3));
            Console.WriteLine();
        }
    }
}